#include <bits/stdc++.h>
using namespace std;
int T, n, a[200003], t;
long long ch, ans;
bool b[21];
int main()
{
    ios::sync_with_stdio(0);
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while(T--)
    {
        ans = 0;
        cin >> n;
        for(int i = 1; i <= n; ++i)
            cin >> a[i];
        for(unsigned long long i = 0; i < 1<<(n-1); ++i)
        {
            ch = 0;
            unsigned long long j = i; t = n;
            while(j)
            {
                b[t--] = j&1;
                j >>= 1;
            }
            int lst[2] = {a[1], 0};
            for(int k = 2; k <= n; ++k)
            {
                if(lst[b[k]] == a[k])
                    ch += a[k];
                lst[b[k]] = a[k];
            }
            if(ch > ans) ans = ch;
        }
        cout << ans << endl;
    }
}